home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / UTILITIE / UNIX_COH / 2774A.ZIP / QQ.CZ / QQ
Text File  |  1991-07-02  |  4KB  |  195 lines

  1. /*
  2.  * qq - sample device driver using absolute memory addressing
  3.  *
  4.  * all this device does is read/write video ram
  5.  *   it assumes that there is a monochrome adapter in use, so that video
  6.  *   ram starts at segment B000; if color, this should be changed to B800
  7.  */
  8. #if 0
  9. Here is the makefile for the "qq" driver (cut it out of this file):
  10. --------------- cut here -----------------
  11. # Make file for a loadable driver
  12.  
  13. AS=exec /bin/as
  14. CC=exec /bin/cc
  15. CPP=exec /lib/cpp
  16. CFLAGS=-I.. -I../sys -I../.. -I../../sys \
  17.     -I/usr/include/sys
  18. AFLAGS=-gx
  19.  
  20. # Include directories
  21. USRINC=/usr/include
  22. SYSINC=/usr/include/sys
  23. KERINC=/usr/src/sys/sys
  24. DRVINC=/usr/src/sys/i8086/sys
  25. USRSYS=/usr/sys
  26.  
  27. DRVOBJ=    objects/qq.o
  28.  
  29. qq: objects/qq.o
  30.     rm -f $(USRSYS)/lib/qq.a
  31.     ar rc $(USRSYS)/lib/qq.a objects/qq.o
  32.  
  33. objects/qq.o:                \
  34.         $(KERINC)/coherent.h    $(SYSINC)/types.h \
  35.                     $(SYSINC)/machine.h $(SYSINC)/param.h \
  36.                     $(SYSINC)/fun.h \
  37.         $(SYSINC)/con.h        \
  38.         $(USRINC)/errno.h    \
  39.         $(SYSINC)/sched.h    \
  40.         $(SYSINC)/seg.h        \
  41.         $(SYSINC)/stat.h    \
  42.         $(SYSINC)/types.h    \
  43.         $(SYSINC)/uproc.h    \
  44.         qq.c
  45.     $(CC) $(CFLAGS) -c -o $@ qq.c
  46. --------------- cut here -----------------
  47. #endif
  48. #include "coherent.h"
  49. #include "ins8250.h"
  50. #include <sys/stat.h>
  51. #include <sys/uproc.h>
  52. #include <sys/proc.h>
  53. #include <sys/con.h>
  54. #include <errno.h>
  55. #include <sys/types.h>
  56. #include <sys/mmu.h>
  57.  
  58. /*
  59.  * Definitions.
  60.  *
  61.  */
  62. #define    MONOVIDEO    0xB000        /* monochrome text RAM segment */
  63. #define    VIDLENGTH    (2048*2)    /* screen locations (2 bytes each) */
  64.  
  65. /*
  66.  * Export Functions.
  67.  */
  68. int    qqload();
  69. int    qqopen();
  70. int    qqclose();
  71. int    qqread();
  72. int    qqwrite();
  73. int    qqunload();
  74.  
  75. /*
  76.  * Import Functions
  77.  */
  78. int    nulldev();
  79. int    nonedev();
  80.  
  81. /*
  82.  * Configuration table.
  83.  */
  84. CON qqcon ={
  85.     DFCHR,                /* Flags */
  86.     7,                /* Major index */
  87.     qqopen,                /* Open */
  88.     qqclose,            /* Close */
  89.     nulldev,            /* Block */
  90.     qqread,                /* Read */
  91.     qqwrite,            /* Write */
  92.     nulldev,            /* Ioctl */
  93.     nulldev,            /* Powerfail */
  94.     nulldev,            /* Timeout */
  95.     qqload,                /* Load */
  96.     qqunload,            /* Unload */
  97.     nulldev                /* Poll */
  98. };
  99.  
  100. /*
  101.  * Local variables.
  102.  */
  103. static faddr_t    screen_fp;        /* (far *) to access screen */
  104. static paddr_t    screen_base;        /* physical address of screen base */
  105.  
  106. /*
  107.  * Load Routine.
  108.  */
  109. static qqload()
  110. {
  111.     /*
  112.      * Allocate a selector to map onto the video RAM.  ptov() will
  113.      * return the first available selector of the 8,192 possible.
  114.      * This is time consuming, so we only want to do this as part
  115.      * of our initialization code and not on every access.
  116.      *
  117.      * Since we are operating in 286 protected mode (ugh), the
  118.      * second argument to ptov() must not exceed 0x10000L.
  119.      */
  120.     screen_base = (paddr_t)MONOVIDEO << 4;
  121.     screen_fp = ptov(screen_base, (fsize_t)VIDLENGTH);
  122. }
  123.  
  124. static qqunload()
  125. {
  126.     /*
  127.      * We have to free up the selector now that we're done using it.
  128.      */
  129.     vrelse(screen_fp);
  130. }
  131.  
  132. /*
  133.  * Open Routine.
  134.  */
  135. qqopen( dev, mode )
  136. dev_t dev;
  137. {
  138. }
  139.  
  140. /*
  141.  * Close Routine.
  142.  */
  143. qqclose( dev )
  144. dev_t dev;
  145. {
  146. }
  147.  
  148. /*
  149.  * Read Routine.
  150.  */
  151. qqread( dev, iop )
  152. dev_t dev;
  153. register IO * iop;
  154. {
  155.     static int offset;
  156.     int c;
  157.     /*
  158.      * Read a character code from video RAM
  159.      * Start reading RAM just after where previous read ended
  160.      *
  161.      * Note that "offset" is the value of the displacement into
  162.      * the screen RAM. Any expression which results in a value
  163.      * which is less than VIDLENGTH is OK here.
  164.      */
  165.     while(iop->io_ioc) {
  166.         c = ffbyte(screen_fp + offset); /* fetch a "far" byte */
  167.         if(ioputc(c, iop) == -1)
  168.             break;
  169.         offset += 2;
  170.         offset %= VIDLENGTH;
  171.     }
  172. }
  173.  
  174. /*
  175.  * Write Routine.
  176.  */
  177. qqwrite( dev, iop )
  178. dev_t dev;
  179. register IO * iop;
  180. {
  181.     int offset = 0;
  182.     int c;
  183.  
  184.     /*
  185.      * Write a character into the screen RAM
  186.      * Note that "offset" is the value of the displacement into
  187.      * the screen RAM. Any expression which results in a value
  188.      * which is less than VIDLENGTH is OK here.
  189.      */
  190.     while ((c = iogetc(iop)) >= 0 && offset < VIDLENGTH) {
  191.         sfbyte(screen_fp + offset, c);       /* store a "far" byte */
  192.         offset += 2;    /* skip attribute byte */
  193.     }
  194. }
  195.